<?php
/**
 * Created by PhpStorm.
 * Author: sitewang@aliyun.com
 * CreateTime: 2023/06/05
 * Blog：www.myblogs.xyz
 */

namespace app\common\service;

class BaseService
{
    protected static $error = '';
    protected static $result = [];

    protected static function setResult($result) : bool
    {
        self::result($result);
        return true;
    }

    // 获取错误提示信息
    public static function getResult() : array
    {
        return self::result();
    }

    protected static function result(array $result = []) : array
    {
        if (!empty($result)){
            self::$result = $result;
        }
        return self::$result;
    }

    protected static function setError(string $error = '') : bool
    {
        self::error($error);
        return false;
    }

    // 获取错误提示信息
    public static function getError() : string
    {
        return self::error();
    }

    protected static function error(string $error = '') : string
    {
        if (!empty($error)){
            self::$error = $error;
        }
        return self::$error;
    }

    public static function orderLen(string $order_code) : bool
    {
        $order_len = strlen($order_code);
        if ($order_len < 6 || $order_len > 64){
            return self::setError('交易订单号，长度允许在6-64位');
        }
        return true;
    }
}